package org.example.boot;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.boot.CommandLineRunner;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.stream.IntStream;

/**
 * @Author: tang
 * @Description:
 * @Date 2025/7/22 10:17
 */
@Slf4j
//@Component
public class ProducerApp implements CommandLineRunner {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void run(String... args) throws Exception {

        IntStream.range(0,10).forEach(i -> {
            rocketMQTemplate.asyncSend("test-topic", "hello world " + i, new SendCallback() {
                @Override
                public void onSuccess(SendResult sendResult) {
                    System.out.println("onSuccess: " + sendResult.toString());
                }

                @Override
                public void onException(Throwable throwable) {
                    log.error("onException: " + throwable.getMessage());
                }
            });
        });
    }
}
